<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('日期分组预测结果列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <p>日期：</p>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreatedate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreatedate]"/>
                            </li>
                            <li>
                                <p>买入：</p>
                                <input type="text" name="buy"/>
                            </li>
                            <li>
                                <p>卖出：</p>
                                <input type="text" name="sell"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="stock2:FORERESULTGROUPBYDATE:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="stock2:FORERESULTGROUPBYDATE:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="stock2:FORERESULTGROUPBYDATE:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('stock2:FORERESULTGROUPBYDATE:edit')}]];
        var removeFlag = [[${@permission.hasPermi('stock2:FORERESULTGROUPBYDATE:remove')}]];
        var prefix = ctx + "stock2/FORERESULTGROUPBYDATE";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                pageSize: 20,
                modalName: "日期分组预测结果",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'createdate',
                    title : '日期',
                    width : '8%',
                    formatter:function (value, row, index) {
                        return value.substr(0,10);
                    }
                },
                {
                    field : 'buy',
                    title : '股票名称',
                    width : '52%',
                    formatter: function(value, row, index) {
                        var buystr = "";
                        var buysz = value.split(",");
                        for(var i=0; i < buysz.length; i++){
                            var namesymbol = buysz[i].split(" ");
                            var name = namesymbol[0];
                            var symbol = namesymbol[1];
                            if(i!=0 && (i+1)%7==0){
                                buystr += name+symbol+"<br>";
                            }else{
                                if(name.length == 3){
                                    buystr += name+symbol+"&nbsp;&nbsp;";
                                }else{
                                    buystr += name+symbol+"&nbsp;";
                                }

                            }

                        }
                        return buystr;
                    }
                },
                {
                    field : 'industry',
                    title : '行业板块',
                    width : '20%'
                    ,formatter: function(value, row, index) {
                        var objectList = new Array();
                        function Persion(name,age){
                            this.name=name;
                            this.age=age;
                        }

                        var industrys = value.split(",")
                        for(var i=0; i < industrys.length; i++){
                            var industry = industrys[i].split("_");
                            var name = industry[0];
                            var number = industry[1];
                            objectList.push(new Persion(name,number));
                        }

                        //按年龄从小到大排序
                        objectList.sort(function(a,b){return b.age - a.age});
                        var buystr = "";
                        for(var i=0;i<objectList.length;i++){

                            if(i!=0 && (i+1)%4==0){
                                buystr += objectList[i].name+objectList[i].age+"个<br>";
                            }else{
                                buystr += objectList[i].name+objectList[i].age+"个&nbsp;&nbsp;&nbsp;";
                            }

                        }

                        return buystr;
                    }

                },
                {
                    field : 'buy',
                    title : '建议',
                    width : '10%',
                    formatter: function(value, row, index) {

                        var size = row.buy.split(",").length;
                        if(size>20){
                            return "行情不错哟</br>有"+size+"个符合要求</br>留意行业大于2个,涨幅大于3%的股票";
                        }else{
                            return "忍住别动手</br>留意行业大于2个,涨幅大于3%的股票";
                        }

                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    width : '10%',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="/stock2/FORERESULTGROUPBYDATE/show/'+row.createdate+'"><i class="fa fa-show"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.createdate + '\')"><i class="fa fa-edit"></i>弹出查看</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>